package com.ms.game.lobby.db;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import com.xpec.c4.db.basic.BasicGameDAO;
import com.xpec.c4.db.hibernate.manager.HibernateBusinessManager;

public class LobbyGameListWhileDAO extends BasicGameDAO
{
	/**
	 * 讀取白名單
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static List<LobbyGameListWhileModel> getAll()
	{
		Session session = HibernateBusinessManager.getSession();
		Query query = session.createQuery("from LobbyGameListWhileModel Where deny=:DENY");
		query.setInteger("DENY", 0);
		return query.list();
	}
	
	/**
	 * 新增白名單資料
	 * @param model
	 * @return
	 */
	public static boolean add(LobbyGameListWhileModel model)
	{
		Session session =  HibernateBusinessManager.txBegin();
		session.saveOrUpdate(model);
		return HibernateBusinessManager.txCommitFailRollbackClearSession();
	}
	
	/**
	 * 更新白名單資料
	 * @param model
	 * @return
	 */
	public static boolean update(LobbyGameListWhileModel model)
	{
		Session session =  HibernateBusinessManager.txBegin();
		session.saveOrUpdate(model);
		return HibernateBusinessManager.txCommitFailRollbackClearSession();
	}
	
	/**
	 * 讀取玩家個人白名單資料
	 * @param playerid
	 * @return
	 */
	public static LobbyGameListWhileModel get(String playerid)
	{
//		Session session  = HibernateManager.getSession();
		Session session =  HibernateBusinessManager.txBegin();
		Query query = session.createQuery("from LobbyGameListWhileModel Where playerid=:ID");
		query.setString("ID", playerid);
		LobbyGameListWhileModel model = (LobbyGameListWhileModel) query.uniqueResult();
		HibernateBusinessManager.txCommitFailRollbackClearSession();
		
		return model;
	}
	
	
}
